package com.zh.supervise.service.impl;


import com.zh.common.dao.DeptDao;
import com.zh.common.dao.UserDao;
import com.zh.common.domain.DeptDO;
import com.zh.common.domain.UserDO;
import com.zh.common.utils.ShiroUtils;
import com.zh.common.utils.StringUtil;
import com.zh.supervise.dao.VisitOldDao;
import com.zh.supervise.domain.VisitOldDO;
import com.zh.supervise.service.VisitOldService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class VisitOldServiceImpl implements VisitOldService {
	@Autowired
	private VisitOldDao visitOldDao;

	@Autowired
	private DeptDao deptDao;

	@Autowired
	private UserDao userDao;
	
	@Override
	public VisitOldDO get(String id){
		return visitOldDao.get(id);
	}
	
	@Override
	public List<VisitOldDO> list(Map<String, Object> map){
		return visitOldDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return visitOldDao.count(map);
	}
	
	@Override
	public int save(VisitOldDO visitOld){
		DeptDO deptDO = deptDao.get(visitOld.getVisitDeptId());
		visitOld.setVisitDeptName(deptDO.getName());
		UserDO userDO = userDao.get(visitOld.getOldUserId());
		visitOld.setOldUserName(userDO.getName());
		visitOld.setId(StringUtil.generalKeyword());
		visitOld.setCreateBy(ShiroUtils.getUser().getName());
		visitOld.setCreateDate(new Date());
		return visitOldDao.save(visitOld);
	}
	
	@Override
	public int update(VisitOldDO visitOld){
		DeptDO deptDO = deptDao.get(visitOld.getVisitDeptId());
		visitOld.setVisitDeptName(deptDO.getName());
		UserDO userDO  = userDao.get(visitOld.getOldUserId());
		visitOld.setOldUserName(userDO.getName());
		visitOld.setUpdateBy(ShiroUtils.getUser().getName());
		visitOld.setUpdateDate(new Date());
		return visitOldDao.update(visitOld);
	}
	
	@Override
	public int remove(String id){
		return visitOldDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return visitOldDao.batchRemove(ids);
	}
	
}
